/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * produto_incluir.java
 *
 * Created on 28/05/2011, 14:52:54
 */
package Visualização;

import javax.swing.JOptionPane;

/**
 *
 * @author Fabio
 */
public class produto_incluir extends javax.swing.JFrame {
    /** Creates new form produto_incluir */
    public produto_incluir() {
        initComponents();
        this.setLocationRelativeTo(null);
        int i;
        String[] c = new String[50];
        BO.produtoBO pBO = new BO.produtoBO();
        Negocio.produto combo = new Negocio.produto();
        combo.PreencherCombo(pBO);
        classificacaoSelect.removeAllItems();
        classificacaoSelect.addItem("        ");
        c=pBO.getVet();
        for(i=0;i<pBO.getTamVet();i++)
            classificacaoSelect.addItem(c[i]);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tituloLabel = new javax.swing.JLabel();
        nomeLabel = new javax.swing.JLabel();
        classificacaoLabel = new javax.swing.JLabel();
        corLabel = new javax.swing.JLabel();
        pesoLabel = new javax.swing.JLabel();
        quantidadeLabel = new javax.swing.JLabel();
        medidasLabel = new javax.swing.JLabel();
        xLabel = new javax.swing.JLabel();
        yLabel = new javax.swing.JLabel();
        zLabel = new javax.swing.JLabel();
        nomeInput = new javax.swing.JTextField();
        pesoInput = new javax.swing.JTextField();
        quantidadeInput = new javax.swing.JTextField();
        gravarButton = new javax.swing.JButton();
        limparButton = new javax.swing.JButton();
        cancelarButton = new javax.swing.JButton();
        classificacaoSelect = new javax.swing.JComboBox();
        corSelect = new javax.swing.JComboBox();
        qtdeminInput = new javax.swing.JTextField();
        qtdeminLabel = new javax.swing.JLabel();
        xInput = new javax.swing.JTextField();
        yInput = new javax.swing.JTextField();
        zInput = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        tituloLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        tituloLabel.setText("Incluir Produto");

        nomeLabel.setText("Nome:");

        classificacaoLabel.setText("Classificação:");

        corLabel.setText("Cor:");

        pesoLabel.setText("Peso:");

        quantidadeLabel.setText("Quantidade:");

        medidasLabel.setText("Medidas:");

        xLabel.setText("x");

        yLabel.setText("y");

        zLabel.setText("z");

        nomeInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nomeInputActionPerformed(evt);
            }
        });

        pesoInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pesoInputActionPerformed(evt);
            }
        });

        quantidadeInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quantidadeInputActionPerformed(evt);
            }
        });

        gravarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Salvar.png"))); // NOI18N
        gravarButton.setText("Gravar");
        gravarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gravarButtonActionPerformed(evt);
            }
        });

        limparButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Limpar.png"))); // NOI18N
        limparButton.setText("Limpar");
        limparButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limparButtonActionPerformed(evt);
            }
        });

        cancelarButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/Cancelar.png"))); // NOI18N
        cancelarButton.setText("Cancelar");
        cancelarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarButtonActionPerformed(evt);
            }
        });

        classificacaoSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        corSelect.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "           ", "alumínio", "amarelo", "argila", "azul", "branco", "cerejeira", "cinza", "grafite", "marfim", "marrom", "mogno", "metálico", "preto", "rosa", "tabaco", "verde", "vermelho", "violeta" }));

        qtdeminInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                qtdeminInputActionPerformed(evt);
            }
        });

        qtdeminLabel.setText("Qtde Mínima:");

        jLabel1.setText("Kg.");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tituloLabel)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(nomeLabel)
                            .addComponent(classificacaoLabel)
                            .addComponent(corLabel))
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(classificacaoSelect, 0, 238, Short.MAX_VALUE)
                            .addComponent(nomeInput, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                            .addComponent(corSelect, 0, 238, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(medidasLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(xInput, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(xLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(yInput, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(yLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(zInput, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(zLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(quantidadeLabel)
                            .addComponent(qtdeminLabel))
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(qtdeminInput, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                            .addComponent(quantidadeInput, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(gravarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(limparButton, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancelarButton))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pesoLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE)
                        .addComponent(pesoInput, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tituloLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nomeLabel)
                    .addComponent(nomeInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(classificacaoLabel)
                    .addComponent(classificacaoSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(corLabel)
                    .addComponent(corSelect, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pesoLabel)
                    .addComponent(pesoInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(quantidadeLabel)
                    .addComponent(quantidadeInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(qtdeminLabel)
                    .addComponent(qtdeminInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(medidasLabel)
                    .addComponent(zLabel)
                    .addComponent(xLabel)
                    .addComponent(yLabel)
                    .addComponent(xInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(yInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(zInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(gravarButton)
                    .addComponent(limparButton)
                    .addComponent(cancelarButton))
                .addContainerGap(26, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void gravarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gravarButtonActionPerformed
        incluir();
    }//GEN-LAST:event_gravarButtonActionPerformed

    private void limparButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limparButtonActionPerformed
        this.nomeInput.setText("");
        this.pesoInput.setText("");
        this.classificacaoSelect.setSelectedIndex(0);
        this.corSelect.setSelectedIndex(0);
        this.quantidadeInput.setText("");
        this.qtdeminInput.setText("");
        this.xInput.setText("");
        this.yInput.setText("");
        this.zInput.setText("");
    }//GEN-LAST:event_limparButtonActionPerformed

    private void cancelarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarButtonActionPerformed
        int op;
        op = JOptionPane.showConfirmDialog(null, "Deseja cancelar a inclusão?", "Cancelar", JOptionPane.YES_NO_OPTION);
        if (op == JOptionPane.YES_OPTION)
            this.dispose();
    }//GEN-LAST:event_cancelarButtonActionPerformed

    private void nomeInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nomeInputActionPerformed
        incluir();
    }//GEN-LAST:event_nomeInputActionPerformed

    private void pesoInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pesoInputActionPerformed
        incluir();
    }//GEN-LAST:event_pesoInputActionPerformed

    private void quantidadeInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quantidadeInputActionPerformed
        incluir();
    }//GEN-LAST:event_quantidadeInputActionPerformed

    private void qtdeminInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_qtdeminInputActionPerformed
        incluir();
    }//GEN-LAST:event_qtdeminInputActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new produto_incluir().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelarButton;
    private javax.swing.JLabel classificacaoLabel;
    private javax.swing.JComboBox classificacaoSelect;
    private javax.swing.JLabel corLabel;
    private javax.swing.JComboBox corSelect;
    private javax.swing.JButton gravarButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JButton limparButton;
    private javax.swing.JLabel medidasLabel;
    private javax.swing.JTextField nomeInput;
    private javax.swing.JLabel nomeLabel;
    private javax.swing.JTextField pesoInput;
    private javax.swing.JLabel pesoLabel;
    private javax.swing.JTextField qtdeminInput;
    private javax.swing.JLabel qtdeminLabel;
    private javax.swing.JTextField quantidadeInput;
    private javax.swing.JLabel quantidadeLabel;
    private javax.swing.JLabel tituloLabel;
    private javax.swing.JTextField xInput;
    private javax.swing.JLabel xLabel;
    private javax.swing.JTextField yInput;
    private javax.swing.JLabel yLabel;
    private javax.swing.JTextField zInput;
    private javax.swing.JLabel zLabel;
    // End of variables declaration//GEN-END:variables
    private void incluir()
    {
        if(verificar()==1)
        {
            int quantidade,  qtdemin;
            float peso, altura, comprimento, largura;
            String aux;
            BO.produtoBO pBO;
            Negocio.produto p;

            pBO = new BO.produtoBO();
            pBO.setNomeBO(this.nomeInput.getText());
            pBO.setCategoriaIdBO(this.classificacaoSelect.getSelectedIndex());
            pBO.setCorBO((String) this.corSelect.getSelectedItem());
            pBO.setPesoBO(Float.parseFloat(this.pesoInput.getText()));
            pBO.setQuantidadeBO(Integer.parseInt(this.quantidadeInput.getText()));
            pBO.setQtdeMinBO(Integer.parseInt(this.qtdeminInput.getText()));
            pBO.setAlturaBO(Float.parseFloat(this.xInput.getText()));
            pBO.setComprimentoBO(Float.parseFloat(this.yInput.getText()));
            pBO.setLarguraBO(Float.parseFloat(this.zInput.getText()));

            p = new Negocio.produto();
            p.SalvarProduto(pBO);
        }
    }
    
    private int verificar()
    {
        if(nomeInput.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Favor preencher o campo Nome!");
            return 0;
        }
        else if (classificacaoSelect.getSelectedIndex()==0)
        {
            JOptionPane.showMessageDialog(null, "Favor escolher o campo Classificação!");
            return 0;
        }
        else if (corSelect.getSelectedIndex()==0)
        {
            JOptionPane.showMessageDialog(null, "Favor escolher o campo Cor!");
            return 0;
        }
        else if (pesoInput.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Favor preencher o campo Peso!");
            return 0;
        }
        else if (quantidadeInput.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Favor preencher o campo Quantidade!");
            return 0;
        }
        else if (qtdeminInput.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Favor preencher o campo Quantidade Mínima!");
            return 0;
        }
        else if (xInput.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Favor preencher o campo Medida!");
            return 0;
        }
        else if (yInput.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Favor preencher o campo Medida!");
            return 0;
        }
        else if (zInput.getText().equals(""))
        {
            JOptionPane.showMessageDialog(null, "Favor preencher o campo Medida!");
            return 0;
        }
        else
            return 1;
    }
}
